﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class UseDetails : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBind_UseDetails(0);
            }
        }

        protected void DataBind_UseDetails(int recordcount)
        {
            int projectId = int.Parse(Request.QueryString["ProjectId"]);
            if (recordcount == 0)
            {
                this.AspNetPager_Content.CurrentPageIndex = 1;
            }
            int count = recordcount;
            int pageIndex = this.AspNetPager_Content.CurrentPageIndex;
            int pageSize = this.AspNetPager_Content.PageSize;
            this.GridView_UseDetails.DataSource = ServiceLocator.ILogService.GetNxUseNumCollection(projectId, pageIndex, pageSize, ref count);
            this.GridView_UseDetails.DataBind();
            this.AspNetPager_Content.RecordCount = count;
        }

        protected void GridView_UseDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            int projectId = int.Parse(Request.QueryString["ProjectId"]);
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                IList project = (IList)e.Row.DataItem;

                Label lbNum = (Label)e.Row.FindControl("lbNum");
                lbNum.Text = (e.Row.RowIndex + 1).ToString();

                Label lbClientName = (Label)e.Row.FindControl("lbClientName");
                lbClientName.Text = Convert.ToString(project[1]);

                Label lbCompany = (Label)e.Row.FindControl("lbCompany");
                lbCompany.Text = Convert.ToString(project[0]);

                Label lbSendTime = (Label)e.Row.FindControl("lbSendTime");
                lbSendTime.Text = Convert.ToString(project[2]);

                Label lbSendNum = (Label)e.Row.FindControl("lbSendNum");
                lbSendNum.Text = "1";//(ServiceLocator.ILogService.GetSendNumByClientId(projectId, Convert.ToInt32(project[4]))).ToString();

                Label lbUseTime = (Label)e.Row.FindControl("lbUseTime");
                lbUseTime.Text = Convert.ToString(project[3]) == "" ? (String)GetGlobalResourceObject("Default","NOT_USED") : Convert.ToString(project[3]);

                Label lbUseNum = (Label)e.Row.FindControl("lbUseNum");
                lbUseNum.Text = Convert.ToString(project[3]) == "" ? "0" : "1";//(ServiceLocator.ILogService.GetUseNumByClientId(projectId, Convert.ToInt32(project[4]))).ToString();
            }
        }

        protected void AspNetPager_Content_PageChanged(object sender, EventArgs e)
        {
            DataBind_UseDetails(this.AspNetPager_Content.RecordCount);
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["BackUrl"] != null)
            {
                Response.Redirect("ProjectStatistics.aspx");
            }
            else
            {
                Response.Redirect("ProjectList.aspx");
            }
        }
    }
}
